<template>
  <j-modal
    :title="title"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">

    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="创建人姓名">
          <a-input placeholder="请输入创建人姓名" v-decorator="['createName', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="创建时间">
          <a-input placeholder="请输入创建时间" v-decorator="['createDate', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="创建时间时分秒">
          <a-input placeholder="请输入创建时间时分秒" v-decorator="['createDateTime', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="更新时间">
          <a-input placeholder="请输入更新时间" v-decorator="['updateDate', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="更新时间时分秒">
          <a-input placeholder="请输入更新时间时分秒" v-decorator="['updateDateTime', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="更新人姓名">
          <a-input placeholder="请输入更新人姓名" v-decorator="['updateName', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="岗位编号">
          <a-input placeholder="请输入岗位编号" v-decorator="['positionCode', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="岗位名称">
          <a-input placeholder="请输入岗位名称" v-decorator="['positionName', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="组织编号">
          <a-input placeholder="请输入组织编号" v-decorator="['orgCode', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="组织名称">
          <a-input placeholder="请输入组织名称" v-decorator="['orgName', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="停用启用状态">
          <a-input placeholder="请输入停用启用状态" v-decorator="['status', validatorRules.status ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="是否删除">
          <a-input placeholder="请输入是否删除" v-decorator="['deleteStatus', validatorRules.deleteStatus ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="备注">
          <a-input placeholder="请输入备注" v-decorator="['remarks', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="saasid">
          <a-input placeholder="请输入saasid" v-decorator="['saasid', validatorRules.saasid ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="线路编号">
          <a-input placeholder="请输入线路编号" v-decorator="['visitId', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="拜访类型(0临时,1拜访2.协访)">
          <a-input-number v-decorator="[ 'visitType', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="被协访线路编号">
          <a-input placeholder="请输入被协访线路编号" v-decorator="['visitAssistId', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="拜访人员岗位">
          <a-input placeholder="请输入拜访人员岗位" v-decorator="['visitPosCode', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="拜访人员岗位名">
          <a-input placeholder="请输入拜访人员岗位名" v-decorator="['visitPosName', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="被协访人岗位">
          <a-input placeholder="请输入被协访人岗位" v-decorator="['visitAssistPosCode', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="被协访人岗位名">
          <a-input placeholder="请输入被协访人岗位名" v-decorator="['visitAssistPosName', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="拜访网点">
          <a-input placeholder="请输入拜访网点" v-decorator="['clientCode', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="拜访网点名">
          <a-input placeholder="请输入拜访网点名" v-decorator="['clientName', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="进店时间">
          <a-input placeholder="请输入进店时间" v-decorator="['visitInTime', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="进店经度">
          <a-input-number v-decorator="[ 'visitInLng', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="进店纬度">
          <a-input-number v-decorator="[ 'visitInLat', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="进度状态">
          <a-input placeholder="请输入进度状态" v-decorator="['visitInStatus', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="离店时间">
          <a-input placeholder="请输入离店时间" v-decorator="['visitOutTime', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="离店经度">
          <a-input-number v-decorator="[ 'visitOutLng', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="离店纬度">
          <a-input-number v-decorator="[ 'visitOutLat', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="离店状态">
          <a-input placeholder="请输入离店状态" v-decorator="['visitOutStatus', {}]" />
        </a-form-item>

      </a-form>
    </a-spin>
  </j-modal>
</template>

<script>
  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import moment from "moment"

  export default {
    name: "SfaVisitInfoModal",
    data () {
      return {
        title:"操作",
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        form: this.$form.createForm(this),
        validatorRules:{
        status:{rules: [{ required: true, message: '请输入停用启用状态!' }]},
        deleteStatus:{rules: [{ required: true, message: '请输入是否删除!' }]},
        saasid:{rules: [{ required: true, message: '请输入saasid!' }]},
        },
        url: {
          add: "/visit/sfaVisitInfoEntity/add",
          edit: "/visit/sfaVisitInfoEntity/edit",
        },
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'createName','createDate','createDateTime','updateDate','updateDateTime','updateName','positionCode','positionName','orgCode','orgName','status','deleteStatus','remarks','saasid','visitId','visitType','visitAssistId','visitPosCode','visitPosName','visitAssistPosCode','visitAssistPosName','clientCode','clientName','visitInTime','visitInLng','visitInLat','visitInStatus','visitOutTime','visitOutLng','visitOutLat','visitOutStatus'))
		  //时间格式化
        });

      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            //时间格式化

            console.log(formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })



          }
        })
      },
      handleCancel () {
        this.close()
      },


    }
  }
</script>

<style lang="less" scoped>

</style>